﻿using BankingApp.Data.Models;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BankingApp.Data
{
    public static class Seeder
    {
        public static void Seed(BankingDbContext context)
        {
            UserStore<User> store = new UserStore<User>(context);
            UserManager<User> manager = new UserManager<User>(store);

            User tre = manager.FindByEmail("tre@gmail.com");

            if (tre == null)
            {
                tre = new User
                {
                    Email = "tre@gmail.com",
                    UserName = "tre@gmail.com"
                };
                manager.Create(tre, "123456");
                tre = manager.FindByEmail("tre@gmail.com");
            }
            User nessa = manager.FindByEmail("nessa@gmail.com");
            if (nessa == null)
            {
                nessa = new User
                {
                    Email = "nessa@gmail.com",
                    UserName = "nessa@gmail.com",
                    
                };
                manager.Create(nessa, "123456");
                nessa = manager.FindByEmail("nessa@gmail.com");
            }
            context.UserAccount.AddOrUpdate(u => u.Name,
               new UserAccount
                {
                    AccountNumber = 0001,
                    Name = "Montre Davis",
                    Balance = 10000,
                    LogInDate = DateTime.Now,
                    User = tre,
                    UserLoginId = "1",
                    
                },
                new UserAccount
                {
                    AccountNumber = 0012,
                    Name = "Vanessa Ramos",
                    Balance = 10000,
                    LogInDate = DateTime.Now,
                    User = nessa,
                    UserLoginId = "2"

                }
                );

        }
    }
}
